/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package cc.ls51.cms.config;

import cc.ls51.cms.interceptor.AuthorizationInterceptor;
import cc.ls51.cms.interceptor.MyProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebMvc配置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    MyProperty myConfig;

    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if(myConfig.isDev()){
            registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
            registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(authorizationInterceptor).addPathPatterns("/**")
        .excludePathPatterns("/static/**");
    }
}